﻿/****************************************************************************
**
*****************************************************************************/

#ifndef MYPUSHBUTTON_H
#define MYPUSHBUTTON_H

#include <QWidget>
#include <QPushButton>
#include <QPainter>
#include <QMouseEvent>
#include <QApplication>

#include "mynamespace.h"

QT_BEGIN_NAMESPACE

class MyPushButtonPrivate;
class MyPushButton : public QPushButton
{
    Q_OBJECT

    Q_PROPERTY(int imageLayerIndex READ getImageLayerIndex WRITE setImageLayerIndex)

    Q_PROPERTY(int deviceIndex READ getDeviceIndex WRITE setDeviceIndex)

    Q_PROPERTY(My::ObjectType objectType READ getObjectType WRITE setObjectType)
    Q_PROPERTY(int objectIndex READ getObjectIndex WRITE setObjectIndex)
    Q_PROPERTY(double data READ getData WRITE setData)

    Q_PROPERTY(bool displayEnable READ getDisplayEnable WRITE setDisplayEnable)
    Q_PROPERTY(bool displayDefault READ getDisplayDefault WRITE setDisplayDefault)

    Q_PROPERTY(My::PushButtonOperate pushButtonOperate READ getPushButtonOperate WRITE setPushButtonOperate)
    Q_PROPERTY(int coilOfRegisterIndex READ getCoilOfRegisterIndex WRITE setCoilOfRegisterIndex)

public:
    explicit MyPushButton(QWidget *parent = nullptr);
    ~MyPushButton();

    /* Property Interface */
    int getImageLayerIndex() const;
    void setImageLayerIndex(int imageLayerInd);

    int getDeviceIndex() const;
    void setDeviceIndex(int deviceInd);

    My::ObjectType getObjectType() const;
    void setObjectType(My::ObjectType);

    int getObjectIndex() const;
    void setObjectIndex(int);

    double getData() const;
    void setData(double);
    void setData(int);

    bool getDisplayEnable() const;
    void setDisplayEnable(bool);

    bool getDisplayDefault() const;
    void setDisplayDefault(bool);

    My::PushButtonOperate getPushButtonOperate() const;
    void setPushButtonOperate(My::PushButtonOperate);

    int getCoilOfRegisterIndex() const;
    void setCoilOfRegisterIndex(int);

protected:
    void paintEvent(QPaintEvent *ev) override;

    void enterEvent(QEvent *ev) override;
    void leaveEvent(QEvent *ev) override;
    void mousePressEvent(QMouseEvent *ev) override;
    void mouseReleaseEvent(QMouseEvent *ev) override;
    void mouseMoveEvent(QMouseEvent *ev) override;

private:
    Q_DISABLE_COPY(MyPushButton)
    MyPushButtonPrivate *d;
};


QT_END_NAMESPACE

#endif // MYPUSHBUTTON_H
